var $operationTable = $("#sysOperationTab");
var $exceptionTable = $("#sysExceptionTab");

$(function () {
    $('#systemlogTab a').click(function(e) {
        e.preventDefault();//阻止a链接的跳转行为  
        layer.closeAll('tips'); //关闭所有的tips层    
        var whichOne = $(this).attr('href');	//获取是点击的哪个
        if(whichOne == "#operation"){
        	initOperationTable();
		}else if(whichOne == "#exception") {
			initExceptionTable();
		}else {
			layer.msg('信息加载有误，请重新打开', {icon:2});
			return;
		}
    }); 
    $('#systemlogTab a[href="#operation"]').trigger('click');
});


//点击系统日志的刷新按钮
function operationReload(){
	$('#systemlogTab a[href="#operation"]').tab('show');
	$operationTable.bootstrapTable('refresh', {url: '../log/getOperationOrExceptionLog.htm?type='+0});
}

//点击系统异常日志的刷新按钮
function exceptionReload(){
	$('#systemlogTab a[href="#exception"]').tab('show');
	$exceptionTable.bootstrapTable('refresh', {url: '../log/getOperationOrExceptionLog.htm?type='+1});
}


function initOperationTable() {
	$operationTable.bootstrapTable({
        dataType: "json",
        pagination: true, //分页
        striped: true,
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        url: '../log/getOperationOrExceptionLog.htm?type=' + 0,
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
			{
				title: "序号",
			    align: 'center',
			    formatter:function(value,row,index){
			    	return index + 1;
			    }
			},
            {
                title: "操作",
                field: "description",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作人",
                field: "createBy",
                align: 'center',
                valign: 'middle'
            },
            {
                title: "操作信息",
                field: "logDetail",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "参数",
            	field: "params",
            	align: "center",
            	formatter: function(value, row, index){
            		var param = row.params;
            		if(param !='' && param !=null && param != undefined){
            			param = param.substr(0,30) + '...';
            		}
            		return param;
            	}
            },
            {
                title: "操作IP",
                field: "requestIp",
                align: 'center',
                valign: 'middle'
            },
            {
                title:"操作时间",
                field:"createDate",
                align: 'center',
                valign: 'middle'
            }
        ],
        onClickCell: function(field, value, row, $element){	//当单击某一格，就会触发该事件，- field：点击此格所在列的field，value：点击列的 value 值 
        	if(field == 'params'){
        		layer.tips(value, $element, {
        			  tips: [2, '#3595CC'],	//靠右出现
        			  time: 8000,	//停留多长时间后自动关闭
        			  area: ['500px', '200px']	//宽-高
        		});
        	}
        },
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
    });
}


function initExceptionTable() {
	$exceptionTable.bootstrapTable({
        dataType: "json",
        pagination: true, //分页
        striped: true,
        pageSize: 10,
        pageNumber: 1,
        queryParamsType: 'limit',
        smartDisplay: true,
        sidePagination: "server",
        method: "post",	//使用post提交
        url: '../log/getOperationOrExceptionLog.htm?type=' + 1,
        contentType: 'application/x-www-form-urlencoded;charset=UTF-8',
        columns: [
			{
				title: "序号",
			    align: 'center',
			    formatter:function(value,row,index){
			    	return index + 1;
			    }
			},
            {
                title: "操作",
                field: "description",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "参数",
            	field: "params",
            	align: "center",
            	formatter: function(value, row, index){
            		var param = row.params;
            		if(param !='' && param !=null && param != undefined){
            			param = param.substr(0,30) + '...';
            		}
            		return param;
            	}
            },
            {
                title: "异常代码",
                field: "exceptionCode",
                align: 'center',
                valign: 'middle'
            },
            {
            	title: "异常信息",
                field: "exceptionDetail",
                align: 'center',
                valign: 'middle'
            },
            {
                title:"操作时间",
                field:"createDate",
                align: 'center',
                valign: 'middle'
            }
        ],
        onClickCell: function(field, value, row, $element){	//当单击某一格，就会触发该事件，- field：点击此格所在列的field，value：点击列的 value 值 
        	if(field == 'params'){
        		layer.tips(value, $element, {
        			  tips: [2, '#3595CC'],	//靠右出现
        			  time: 8000,	//停留多长时间后自动关闭
        			  area: ['500px', '200px']	//宽-高
        		});
        	}
        },
        onClickRow: function(row, $element, field){	//当点击某一行时，该行背景颜色改变
        	var trObj = $($element[0]);
        	var dataIndex = trObj.attr('data-index');
        	$("tr[data-index != '" + dataIndex + "']").removeAttr('style');
        	trObj.attr('style', 'background: #B4EEB4');
        }
    });
}

